from manimlib import *

sys.path.append('.')
from customized import *


class p1(Scene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        ax = Axes(
            x_range=[-2, 2, 1],
            y_range=[-1, 3, 1],
            width=6,
            height=6,
        ).set_color(BLACK)
        parabola = ax.get_graph(lambda x: x ** 2, x_range=[-1.5, 1.5],color=BLACK)
        o = ax.coords_to_point(0, 5 / 4, 0)
        circle = CustomizedCircle(radius=1.5).move_to(o)
        x, y = np.sqrt(3) / 2, 3 / 4
        diff = Difference(ax.get_graph(lambda x: x ** 2, x_range=[-x, x]), circle).set_fill(LV, 1).set_stroke(BLACK)
        self.add(parabola, circle, ax, diff)


class p2(Scene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        ax = Axes(
            x_range=[-2, 2, 1],
            y_range=[-1, 3, 1],
            width=6,
            height=6,
        ).set_color(BLACK)
        parabola = ax.get_graph(lambda x: x ** 2, x_range=[-1.5, 1.5]).set_color(BLACK)
        o = ax.coords_to_point(0, 5 / 4, 0)
        circle = CustomizedCircle(radius=1.5).move_to(o)
        x, y = np.sqrt(3) / 2, 3 / 4
        diff = Difference(ax.get_graph(lambda x: x ** 2, x_range=[-x, x]), circle).set_fill(LV, 1).set_stroke(BLACK)
        self.add(parabola, circle, ax, diff)
        # p2
        a, b, c, d = ax.coords_to_point(-x, y, 0), ax.coords_to_point(x, y, 0), ax.coords_to_point(x, 0,
                                                                                                   0), ax.coords_to_point(
            -x, 0, 0)
        oa, ob = CustomizedLine(o, a), CustomizedLine(o, b)
        self.add(oa, ob,
                 DashedLine(a, b).set_color(BLACK),
                 DashedLine(b, c).set_color(BLACK),
                 DashedLine(d, a).set_color(BLACK),
                 CustomizedTex(r'O(0,\frac{5}{4})').next_to(o, UR),
                 CustomizedTex(r'A(-\frac{\sqrt{3}}{2},\frac{3}{4})').next_to(a, LEFT),
                 CustomizedTex(r'B(\frac{\sqrt{3}}{2},\frac{3}{4})').next_to(b),
                 CustomizedTex(r'C(\frac{\sqrt{3}}{2},0)').next_to(c, DOWN),
                 CustomizedTex(r'D(-\frac{\sqrt{3}}{2},0)').next_to(d, DOWN)
                 )
